import React, { ReactNode } from 'react';
import styles from './index.module.scss';
import classNames from 'classnames';

// 1. 定义PropsTYpe的类型(改造为interface类型)
interface IInputProps
  // 借鉴内置类型,继承内置类型
  extends React.DetailedHTMLProps<
    React.InputHTMLAttributes<HTMLInputElement>,
    HTMLInputElement
  > {
  // 可选的
  className?: string;
  extra?: ReactNode;
  errorMsg?: string;
  // [key: string]: any;
}

export default function Input(props: IInputProps) {
  // 解构透传剩余属性
  const { className, extra, errorMsg, ...restProps } = props;
  return (
    <div className={classNames(styles.root, className)}>
      <div className="input-item">
        <div className="input-box">
          <input className="input" {...restProps} />
          {/* 2. 解构插值，放置内容 */}
          <div className="validate">{errorMsg}</div>
          <div className="extra">{extra}</div>
        </div>
      </div>
    </div>
  );
}
